package org.usmile.algorithms.huawei.acm;

import java.util.*;


// https://fcqian.blog.csdn.net/article/details/128816967
public class _最多几个直角三角形 {
    private final static Map<Integer, Map<Integer, Integer>> numCountMap = new HashMap<>();
    private static int[][] cases;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        cases = new int[t][];
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            Map<Integer, Integer> numCount = new HashMap<>();
            for (int j = 0; j < n; j++) {
                int num = sc.nextInt();
                arr[j] = num;
                numCount.put(num, numCount.getOrDefault(num, 0) + 1);
            }
            cases[i] = arr;
            numCountMap.put(i, numCount);
        }

        getResult();
    }

    public static void getResult() {
        for (int i = 0; i < cases.length; i++) {
            int[] nums = cases[i];
            // 对每组测试线段升序排序
            Arrays.sort(nums);
            Map<Integer, Integer> numCount = numCountMap.get(i);
            ArrayList<Integer[]> combines = new ArrayList<>();
            dfs(nums, 0, new LinkedList<>(), combines);
            ArrayList<Integer[]> ans = new ArrayList<>();
            for (Integer[] combine : combines) {
                boolean canCombine = true;
                for (int num : combine) {
                    if (numCount.get(num) <= 0) {
                        canCombine = false;
                        break;
                    }
                }
                if (canCombine) {
                    for (int num : combine) {
                        numCount.put(num, numCount.get(num) - 1);
                    }

                    ans.add(combine);
                }
            }

            for(Integer[] re : ans) {
                System.out.println(Arrays.deepToString(re));
            }
        }
    }

    // 全组合求解，即n个数中选3个
    public static void dfs(int[] arr, int index, LinkedList<Integer> path, ArrayList<Integer[]> combines) {
        if (path.size() == 3) {
            if (isRightTriangle(path)) {
                combines.add(path.toArray(new Integer[3]));
            }
            return;
        }

        for (int i = index; i < arr.length; i++) {
            path.add(arr[i]);
            dfs(arr, i + 1, path, combines);
            path.removeLast();
        }
    }

    // 判断三条边是否可以组成直角三角形
    public static boolean isRightTriangle(LinkedList<Integer> path) {
        // 注意，path中元素是升序的，因为path是取自arr的组合，而arr是升序的
        int x = path.get(0);
        int y = path.get(1);
        int z = path.get(2);

        return x * x + y * y == z * z;
    }
}
